﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.ViewModel;
using ZhouYu.DreamTour.Web.Models;

namespace ZhouYu.DreamTour.Web.Controllers
{
    public class SpecialtyController : Controller
    {

        private ISpecialtyService _specialtyService;
        public SpecialtyController(ISpecialtyService specialtyService)
        {
            _specialtyService = specialtyService;
        }


        /// <summary>
        /// 添加商品订单信息
        /// </summary>
        /// <returns></returns>
        public JsonResult AddGoodsOrderInfo(OrderAndOver orderAndOver)
        {
            //创建订单对象
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.User_Id = UserInfoContext.userInfoContext.UserInfo.User_Id;
            orderInfo.Order_ProInfo = orderAndOver.Order_ProInfo;
            orderInfo.Order_Money = orderAndOver.Order_Money;
            orderInfo.Order_Content = orderAndOver.Order_Content;
            orderInfo.Orde_PictureUrl = orderAndOver.Orde_PictureUrl;
            orderInfo.Order_No = orderAndOver.Order_No;
            //调用添加商品订单信息
            ResponseResult responseResult = _specialtyService.AddGoodsOrderInfo(orderInfo);
            if (responseResult.Success)
            {
                //调用根据用户Id查询最新一条订单
                OrderInfo orderInfo1 = _specialtyService.CheckNewOrder(orderInfo.User_Id).data;
                //创建订单收货对象
                OrderOver orderOver = new OrderOver();
                orderOver.Order_Id= orderInfo1.Order_Id;
                orderOver.OrderOver_Address = orderAndOver.OrderOver_Address;
                orderOver.OrderOver_Tel = orderAndOver.OrderOver_Tel;
                orderOver.OrderOver_Name = orderAndOver.OrderOver_Name;
                //添加订单时同时将收货人信息添加到订单收货中
                responseResult = _specialtyService.AddOrderNowToOrderOver(orderOver);
            }
            return Json(responseResult);
        }

        #region 根据订单编号修改订单状态为待评价
        /// <summary>
        /// 根据订单编号修改订单状态为待评价
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateOrderStatusByOrder_No(string Order_No) {
            //调用根据订单编号修改订单状态为待评价
            ResponseResult responseResult = _specialtyService.UpdateOrderStatusByOrder_No(Order_No);
            return Json(responseResult);
        }
        #endregion
    }
}